home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93a.txt
/
000111_icon-group-sender _Fri Apr 2 15:06:23 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1993-04-21
|
3KB
Received: by cheltenham.cs.arizona.edu; Sat, 10 Apr 1993 10:27:38 MST
Date: 2 Apr 93 15:06:23 GMT
From: uchinews!ellis!goer@speedy.wisc.edu (Richard L. Goerwitz)
Organization: University of Chicago
Subject: Re: Icon rookie problems solved
Message-Id: <1993Apr2.150623.19869@midway.uchicago.edu>
References: <9364@kielo.uta.fi>
Sender: icon-group-request@cs.arizona.edu
To: icon-group@cs.arizona.edu
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
In article <9364@kielo.uta.fi> jere@uta.fi (Jere K{pyaho) writes:
>For the record, here is my solution:
>
>procedure genchar( s, c )
> s ? {
> every i := upto( c ) do {
> tab( i )
> write( move( i ) )
> }
> }
>end
>
>
>Although I'm fascinated by Icon, I don't find this example
>too intuitive.
You made the scanning expression the outside enclosing control
structure, which is great. Here's another general rule: If you
are using "every" within a scanning expression, you're doing some-
thing wrong. This rule isn't hard and fast, and you certainly
shouldn't feel bad about using it above. If we remove it and the
intermediate variable, though, we get something a bit more elegant
and (to most Icon programmers) more intuitive:
(1)
s ? {
while tab( upto(c) ) do
write( move(1) )
}
You may remember that the do-clause can be omitted, so you can do
this more compactly:
(2)
s ? while write( (tab(upto(c)), move(1)) )
Note that (2) uses the (a,b) construct. a & b might just as well
have been used. In either case, a must succeed and produce a re-
sult before b will be tried. What this does is make it so that,
for every time tab(upto(c)) succeeds, move(1) will be executed,
and the expression as a whole (either (a,b) or a & b) will produce
the result of b, i.e. the result of move(1):
(2)
s ? while write( tab(upto(c)) & move(1) )
Both of these seem to me to be idiomatic Icon code, although it
is true that opinions differ. Some prefer (1). Some prefer (3)
to (2). I don't like (2) because it looks messy :-).
The key to scanning is that scanning handles all of your place-
keeping for you, so you don't have to use "every" or the like.
When I tab( upto(c) ), then the first result produced by upto(c)
is where I tab to, and that becomes my position (my &pos, in Icon's
terms). If I want the next c, I can just move(1) past the current
c, and then do another tab( upto(c) ). Icon knows where I am in
the string, and I don't have to keep track of it myself. The next
time I tab( upto(c) ) I'll end up at the next match!
As a result of this, your
every i := upto(c)
is a neat idea (i.e. produce all the positions at which c chars
occur). But it's almost too clever. By simply doing a
while tab( upto(c) ) do
write( move(1) )
you are moving up to successive positions at which c occurs, then
move()ing past them and printing the character matched - and this
without using an i variable or any every structures (which tend
to be counterintuitive within scanning expressions).
Hope this helps.
Regarding 32-bit Icon: Icon is really meant for CPUs and OSs
that operate in a larger address space than DOS machines tradi-
tionally offer. Not that the DOS implementation is a bad one.
It's amazingly clever, in fact.
--
-Richard L. Goerwitz goer%midway@uchicago.bitnet
goer@midway.uchicago.edu rutgers!oddjob!ellis!goer